package model.components.links.factory;

import model.components.links.link.VirtualLink;

public class VirtualLinksFactory extends LinksFactory
{	
	public static final int MIN_BANDWIDTH = 1;
	public static final int MAX_BANDWIDTH = 50;
	
	public static final int VLANS_PERCENTAGE = 34;
	public static final int SDH_SONET_PERCENTAGE = 33;
	public static final int EIGHT0211_PERCENTAGE = 33;
	
	private int startingDate;
	public int getStartingDate(){ return startingDate; }
	public void setStartingDate( int startingDate ){ this.startingDate = startingDate; }
	
	private int endingDate;
	public int getEndingDate(){ return endingDate; }
	public void setEndingDate( int endingDate ){ this.endingDate = endingDate; }
	
	protected int vlanPercentage;
	public int getVlanPercentage(){ return this.vlanPercentage; }
	public void setVlanPercentage( int vlanPercentage ){ this.vlanPercentage = vlanPercentage; }
	
	protected int sonetPercentage;
	public int getSonetPercentage(){ return this.sonetPercentage; }
	public void getSonetPercentage( int sonetPercentage ){ this.sonetPercentage = sonetPercentage; }
	
	protected int eight0211percentage;
	public int getEight0211percentage(){ return this.eight0211percentage; }
	public void setEight0211percentage( int eight0211percentage ){ this.eight0211percentage = eight0211percentage; }

	public VirtualLinksFactory( String networkName, int startingDate, int endingDate )
	{
		super( networkName, MIN_BANDWIDTH, MAX_BANDWIDTH );
		
		this.setStartingDate( startingDate );
		this.setEndingDate( endingDate );
		
		this.setVlanPercentage( VLANS_PERCENTAGE );
		this.getSonetPercentage( SDH_SONET_PERCENTAGE );
		this.setEight0211percentage( EIGHT0211_PERCENTAGE );
	}
	
	public VirtualLinksFactory( String networkName, int startingDate, int endingDate, int minBandwidth, int maxBandwidth, int vlanPercentage, int sonetPercentage, int eight0211Percentage )
	{
		super( networkName, minBandwidth, maxBandwidth );
		
		this.setStartingDate( startingDate );
		this.setEndingDate( endingDate );
		
		this.setVlanPercentage( vlanPercentage );
		this.getSonetPercentage( sonetPercentage );
		this.setEight0211percentage( eight0211Percentage );
	}
	
	@Override
	public VirtualLink create()
	{
		VirtualLink virtualLink = new VirtualLink( this.getNetworkName(), this.getStartingDate(), this.getEndingDate(), this.getLinkCount(), this.randomType(), this.randomBandwidth() );
		this.setLinkCount( this.getLinkCount() + 1 );
		
		return virtualLink;
	}
	private String randomType()
	{
		int randomTypePercentage = (int) (100 * Math.random());
		
		if( 0 <= randomTypePercentage && randomTypePercentage < this.getVlanPercentage() )
			return VirtualLink.VLAN_TYPE;
		
		else if( this.getVlanPercentage() <= randomTypePercentage && randomTypePercentage < this.getVlanPercentage() + this.getSonetPercentage() )
			return VirtualLink.SONET_TYPE;
		
		else if( this.getVlanPercentage() + this.getSonetPercentage() <= randomTypePercentage && randomTypePercentage < 100 )
			return VirtualLink.EIGHT0211_TYPE;
		
		return null;
	}
	
}
